// 忘记密码设置新的密码
$(function() {
	// pwd1RegFlag pwdSameFlag pwd1Tip
	var pwdReg = /^.{6,20}$/;// 长度大于6位小于20的密码正则表达式
	$("#pwd1").bind("input propertychange change", function(event) {
		verifyPwd1();
	})
	function verifyPwd1() {
		var pwd1 = $("#pwd1").val();
		if (!pwdReg.test(pwd1)) {
			$("#pwd1Tip").css("display", "block");
			$("#pwd1RegFlag").attr("value", "false");
		} else {
			$("#pwd1Tip").css("display", "none");
			$("#pwd1RegFlag").attr("value", "true");
		}
	}
	$("#pwd1").blur(function() {
		verifyPwd1();
	})

	// 判断两次输入的密码是否一致
	$('#pwd2').bind("input propertychange change", function(event) {
		verifyPwd2();
	})
	function verifyPwd2() {
		var pwd1 = $("#pwd1").val();
		var pwd2 = $("#pwd2").val();
		if (pwd1 == pwd2) {
			$("#pwd2Tip").css("display", "none");
			$("#pwdSameFlag").attr("value", "true");
		} else {
			$("#pwd2Tip").css("display", "block");
			$("#pwdSameFlag").attr("value", "false");
		}
	}
	$("#pwd2").blur(function() {
		verifyPwd2();
	})

	// 提交数据
	$("#J-m-submit")
			.click(
					function() {
						verifyPwd1();
						verifyPwd2();
						var pwd = $("#pwd2").val();
						var uId = $("#uId").attr("value");
						var data = {
							"pwd" : pwd,
							"uId" : uId
						};
						var pwdSameFlag = $("#pwdSameFlag").attr("value");
						var pwd1RegFlag = $("#pwd1RegFlag").attr("value");
						if (pwdSameFlag == "true" && pwd1RegFlag == "true") {
							console.log("提交数据获取密码的值" + pwd);
							$
									.ajax({
										type : 'post',
										url : '/tenement/modifyPwd.action',
										data : JSON.stringify(data),
										contentType : "application/json;charset=utf-8",
										success : function(msg) {
											if (msg == 1) {
												window.location.href = "../../../../../toPersonModifyPwdHtml3.action";
											} else {
												alert("修改失败");
											}
										}
									})
						}
					})

});